package com.company.OfferGuide;

public class 翻转单词顺序 {

    //注意空串

    public String reverseWords(String s) {
        String[] strings = s.split(" ");
        StringBuilder builder = new StringBuilder();
        for (int i = strings.length - 1; i >= 0; i--) {
            if (strings[i].trim().length() > 0)
                if (i == 0)  {
                    builder.append(strings[i]);
                } else {
                    builder.append(strings[i]).append(" ");
                }

        }
        return builder.toString().trim();
    }

}
